<?php /*a:1:{s:102:"E:\hisiphp_cms_1.0\the-first-project---wxcms\thinkphp5.1\tp5\application\admin\view\article\index.html";i:1616675673;}*/ ?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>文章管理</title>
    <link href="/component/pear/css/pear.css" rel="stylesheet" />
</head>
<body class="pear-container">
<div class="layui-card">
    <div class="layui-card-body">
        <div>
            <b>
                <i>文章管理</i>
            </b>
        </div>
    </div>
</div>
<div class="layui-card">
    <div class="layui-card-body">
        <table id="role-table" lay-filter="role-table"></table>
    </div>
</div>


<script type="text/html" id="role-bar">
    <button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="edit"><i class="layui-icon layui-icon-edit"></i></button>
    <?php if(!isset($error)): ?>
    <button class="pear-btn pear-btn-danger pear-btn-sm" lay-event="remove"><i class="layui-icon layui-icon-delete"></i></button>
    <?php endif; ?>
</script>

<script type="text/html" id="role-enable">
    <input type="checkbox" name="{{d.status}}" value="{{d.id}}" lay-skin="switch" lay-text="启用|禁用" lay-filter="user-enable"
           {{d.status == 1 ? "checked" : ""}}>
</script>

<script src="/component/layui/layui.js"></script>
<script src="/component/pear/pear.js"></script>
<script>
    layui.use(['table','form','jquery'],function () {
        let table = layui.table;
        let form = layui.form;
        let $ = layui.jquery;

        let cols = [
            [
                {title: '作者', field: 'author', align:'center', width:100},
                {title: '标题', field: 'title', align:'center'},
                {title: '简介', field: 'content', align:'center'},
                {title: '发布时间', field: 'create_time', align:'center'},
                {title: '修改时间', field: 'update_time', align:'center'},
                {title: '状态', field: 'status', align:'center', templet:'#role-enable'},
                {title: '操作', toolbar: '#role-bar', align:'center', width:195}
            ]
        ]

        table.render({
            elem: '#role-table',
            url: '<?php echo url("admin/article/getArticleAll"); ?>',
            page: true ,
            cols: cols ,
            skin: 'line',
            toolbar: '#role-toolbar',
            defaultToolbar: [{
                title: '刷新',
                layEvent: 'refresh',
                icon: 'layui-icon-refresh',
            }, 'filter', 'print', 'exports']
        });

        table.on('tool(role-table)', function(obj){
            if(obj.event === 'remove'){
                window.remove(obj);
            } else if(obj.event === 'edit'){
                window.edit(obj);
            } else if(obj.event === 'power'){
                window.power(obj);
            }
        });


        /**
         * 修改状态
         */
        form.on('switch(user-enable)', function(obj) {
            layer.tips(this.value + ' ' + this.name + '：' + obj.elem.checked, obj.othis);
            let _this = this;
            $.ajax({
                url : "<?php echo url('admin/article/updateStatus'); ?>",
                type : "post",
                async : true,
                data : {
                    id : _this.value,
                    status : _this.name
                },
                dataType : "JSON",
                success (res) {
                    if (res.code === 1) {
                        if (_this.name === 1) {
                            $(_this).removeAttr("checked");
                            $(_this).val(0);
                        } else {
                            $(_this).prop("checked",true);
                            $(_this).val(1);
                        }
                    } else {
                        layer.msg(res.msg, {
                            icon: 2,
                            time: 1000
                        });
                    }
                },
                error (res) {

                }
            });

        });

        window.edit = function(obj){
            layer.open({
                type: 2,
                title: '修改',
                shade: 0.1,
                area: ['900px', '600px'],
                content: "<?php echo url('admin/article/edit'); ?>?id=" + obj.data.id
            });
        }

        window.remove = function(obj){
            layer.confirm('确定要删除该文章', {icon: 3, title:'提示'}, function(index){
                $.ajax({
                    url : "<?php echo url('admin/article/delete'); ?>",
                    dataType : 'json',
                    type : 'post',
                    data : {
                        id : obj.data['id']
                    },
                    success (res) {
                        if (res.code === 1) {
                            layer.open({
                                title :  res.msg,
                                content : res.data,
                            });
                            obj.tr.remove();
                        } else {
                            layer.open({
                                title : res.msg,
                                content : res.data
                            });
                        }
                    }
                })
            });
        }


    })
</script>
</body>
</html>
